/*
 * Copyright (c) 2016, Seer Tech co. tld. All rights reserved.
 * SEER TECH PROJECT: lichen. Use is subject to license terms.
 *
 *
 *
 *
 *
 */
package com.mass.core.framework.web.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * Your class description. <p />
 *
 * @author tuyan
 * @version 1.0.0
 * @date 16/8/29 上午11:17
 * @see
 * @since JDK1.7
 */
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {

    public XssHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    
    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);
        if (values==null)  {
            return null;
        }
        int count = values.length;
        String[] encodedValues = new String[count];
        for (int i = 0; i < count; i++) {
            encodedValues[i] = cleanXSS(values[i]);
        }
        return encodedValues;
    }

    
    public String getParameter(String name) {
        String value = super.getParameter(name);
        if (value == null) {
            return null;
        }
        return cleanXSS(value);
    }

    private String cleanXSS(String value) {
        //You'll need to remove the spaces from the html entities below
//        value = StringEscapeUtils.escapeHtml(value);
//        value = StringUtils.htmlEncode(value);
//        value = StringEscapeUtils.escapeJavaScript(value);
//        value = StringEscapeUtils.escapeSql(value);
        return value;
    }
}
